package com.ruoyi.common.base.biz.service.extend;

import cn.hutool.core.util.ObjectUtil;
import com.ruoyi.common.base.biz.service.base.BaseService;
import com.ruoyi.common.core.domain.BizBaseEntity;
import com.ruoyi.common.exception.GlobalException;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * BaseServiceExtendImpl
 *
 * @author ZhengJun
 * @since 2023/6/7 21:15
 */
public class BaseExtendServiceImpl<E extends BizBaseEntity, Do extends E, Po extends E, S extends BaseService<E, Do, Po>>
        implements BaseExtendService<E, Do, Po>
{
    @Autowired
    protected S service;

    public S getService()
    {
        return this.service;
    }

    @Override
    public String getModelName() {
        return "";
    }

    @Override
    public Po getPoByIdNotNull(Long id)
    {
        Po po = this.getService().getPoById(id);
        if (ObjectUtil.isNull(po)) {
            throw new GlobalException(this.getModelName() + "数据不存在");
        }
        return po;
    }

    @Override
    public E getByIdNotNull(Long id)
    {
        E entity = this.getService().getById(id);
        if (ObjectUtil.isNull(entity)) {
            throw new GlobalException(this.getModelName() + "数据不存在");
        }
        return entity;
    }
}
